import React from 'react'
import { useDispatch, useSelector } from "react-redux";
import { increment, decrement } from '../../store/slice/counSlice'
export default function Count() {
  const dispacth = useDispatch()
  const count = useSelector(state => state.count.count)
  const movieList = useSelector(state => state.movie.movieList)

  const incrementHandle = () => {
    // console.log(increment);
    dispacth(increment(10))
  }

  const decreamentHandle = () => {
    dispacth(decrement(1))
  }

  const ifOddDecrementHandle = () => {
    if (count % 2 !== 0) {
      dispacth(increment(5))
    }
  }

  const waitDecrementHandle = () => {
  }



  return (
    <div>
      <h1>我是Count组件 我的值是{count}</h1>
      <h2>当前的电影总是数 {movieList.length}</h2>
      <div>
        <button onClick={incrementHandle}>累加</button>
        <button onClick={decreamentHandle}>累减</button>
        <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
        <button onClick={waitDecrementHandle}>等2s再加1</button>
      </div>

    </div>
  )
}
